﻿using System;
using System.Windows;
using System.Windows.Browser;
using System.Windows.Controls;

namespace Rio.Framework.Pages
{
	public partial class SplashScreen : UserControl
	{
        public event EventHandler StopCurrentAction;
        
        public String Message
        {
            get { return (String)GetValue(MessageProperty); }
            set { SetValue(MessageProperty, value); }
        }
        public static readonly DependencyProperty MessageProperty = 
            DependencyProperty.Register("Message", typeof(String), typeof(SplashScreen), new PropertyMetadata(String.Empty));

        public String MessageDetail
        {
            get { return (String)GetValue(MessageDetailProperty); }
            set { SetValue(MessageDetailProperty, value); }
        }
        public static readonly DependencyProperty MessageDetailProperty = 
            DependencyProperty.Register("MessageDetail", typeof(String), typeof(SplashScreen), new PropertyMetadata(String.Empty));

		public SplashScreen()
		{
			InitializeComponent();
            
            HtmlPage.Plugin.Focus();
		}

        public SplashScreen(string p_sMessage)
            : this()
        {
            Message = p_sMessage;
        }

        /// <summary>
        /// Show the screen
        /// </summary>
        public void Show()
        {
            CancelBtn.Visibility = StopCurrentAction == null ? Visibility.Collapsed : Visibility.Visible;
        }

        /// <summary>
        /// Close the screen
        /// </summary>
        public void Close()
        {
            CancelBtn.Visibility = Visibility.Collapsed;
        }

        /// <summary>
        /// Called when StopCurrentAction.
        /// </summary>
        private void OnStopCurrentAction()
        {
            if (StopCurrentAction != null)
            {
                StopCurrentAction(this, null);
            }
        }

        /// <summary>
        /// Handles the Click event of the CancelBtn control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.Windows.RoutedEventArgs"/> instance containing the event data.</param>
        private void CancelBtn_Click(object sender, RoutedEventArgs e)
        {
            OnStopCurrentAction();
        }
	}
}